package com.jiangyg.mall.core.enums;

import org.apache.commons.lang.StringUtils;

import java.util.Arrays;

/**
 * 枚举描述：启用标志
 *
 * @author jiangyg
 * @version 2.0
 * @date 2019-10-17
 */
public enum Enable {

    Y("Y", 1, "启用"), N("N", 0, "禁用");

    /**
     * 字符串类型代码
     */
    public final String scode;

    /**
     * 数值类型代码
     */
    public final int icode;

    /**
     * 名称
     */
    public final String name;

    Enable(String scode, int icode, String name) {
        this.scode = scode;
        this.icode = icode;
        this.name = name;
    }

    /**
     * 功能描述：根据代码判断值
     *
     * @param code 代码
     * @return Enable
     */
    public static Enable decide(Object code) {
        if (code != null && code instanceof String) {
            return Arrays.stream(Enable.values()).filter(item -> code.equals(item.scode)).findFirst().orElse(null);
        }
        if (code != null && code instanceof Integer) {
            return Arrays.stream(Enable.values()).filter(item -> code.equals(item.icode)).findFirst().orElse(null);
        }
        return null;
    }

    @Override
    public String toString() {
        return "Enable [scode=" + this.scode + ", icode=" + this.icode + ", name=" + this.name + "]";
    }

}
